package com.itheima.dubbo.mysql.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.commons.pojo.domain.Announcement;
import com.itheima.dubbo.interfaces.AnnouncementApi;
import com.itheima.dubbo.mysql.mapper.AnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author yaohu
 * @date 2021/12/12
 * @Version 1.0
 * @describe
 */
@Service
public class AnnouncementApiImpl implements AnnouncementApi {

    @Autowired
    private AnnouncementMapper announcementMapper;

    /**
     * 分页查询公告
     *
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public List<Announcement> findAnnouncementByPage(Integer page, Integer pageSize) {
        Page<Announcement> selectPage = announcementMapper.selectPage(new Page<>(page, pageSize),
                Wrappers.lambdaQuery(Announcement.class).orderByDesc(Announcement::getCreated));
        return selectPage.getRecords();
    }
}
